package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.anno.RecodeTimeAnno;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.service.DeptService;
import com.itheima.utils.TliasException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-04 10:18
 **/
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper,Dept> implements DeptService {

    @Autowired
    private EmpMapper empMapper;
    /**
     * 查询所有部门
     * @return 部门对象集合
     *//*
    @Override
    @RecodeTimeAnno
    public List<Dept> selectDeptList() {
        List<Dept> list = deptMapper.selectDeptList();
        return list;
    }
    *//**
     * 根据id删除部门
     * @param id 部门id
     * @return 影响的行数
     */
    @Override
    public void delDeptById(Integer id) {
      // 判断该部门下面是否有员工
      LambdaQueryWrapper<Emp> lambdaQueryWrapper = new LambdaQueryWrapper<>();
      lambdaQueryWrapper.eq(Emp::getId,id);
      Long count = empMapper.selectCount(lambdaQueryWrapper);
      if (count>0){
          throw new TliasException("部门下有员工，不能删除");
      }
      this.removeById(id);

    }
    /**
     * 根据id查询部门
     * @param id 部门id
     * @return 部门对象
     *//*
    @Override
    public Dept getDeptById(Integer id) {
       Dept dept = deptMapper.getDeptById(id);
       return dept;
    }
    *//**
     * 增加部门
     * @param dept 部门对
     * @return 影响的行数
     *//*
    @Override
    public Integer addDept(Dept dept) {
        // 辅助属性补全
        LocalDateTime localDateTime = LocalDateTime.now();
        dept.setCreateTime(localDateTime);
        dept.setUpdateTime(localDateTime);
        Integer num = deptMapper.addDept(dept);
        return num;
    }
    *//**
     * 修改部门
     * @param dept 部门对
     * @return 影响的行数
     *//*
    @Override
    public Integer updateDeptById(Dept dept) {
        LocalDateTime localDateTime = LocalDateTime.now();
        dept.setUpdateTime(localDateTime);
        Integer num = deptMapper.updateDeptById(dept);
        return num;
    }*/
}
